package com.wch.SpringBootTestDemo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.wch.SpringBootTestDemo.entity.User;
import com.wch.SpringBootTestDemo.service.RedisService;
import com.wch.SpringBootTestDemo.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;


@SuppressWarnings("all")
//@Controller
@RequestMapping("/userContrlloer")
@RestController
@Api(value = "测试接口", tags = "用户管理相关的接口", description = "用户测试接口")
//@Api(value = "te")
public class UserController {

    private final static Logger logger = LoggerFactory.getLogger(UserController.class);
    
    @Autowired
	private RedisTemplate redisTemplate;

    
    @Autowired
    private UserService userService;
    
    /**
	 * 20190124 add by WanChengHe 
	 * 用于测试配置的redis 
	 * 思路：获取用户信息，默认先从redis中取，如果取到了就直接返回，如果没取到就查数据库，获取数据库中数据写入到redis并返回信息
	 * @return
	 */
    @RequestMapping(value="/{userName}",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "方法描述 ", notes="提示内容")
	@ApiResponses(value = {@ApiResponse(code=200,response=String.class,message="成功")})
	public String getUserInfo(@PathVariable("userName")String userName){
		logger.info("前台获取用户名信息为："+userName);
		
		User user = userService.getUserInfoByName(userName);
		return user.toString();
	}
	
	


}
